<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\common\library\Daili;
use app\common\library\Game;
use app\common\library\Wxpay;
use think\Db;
use think\Cache;
use think\Loader;
use think\Hook;
//use  extend\org;
class Biquan extends Frontend
{

	protected $noNeedLogin = ['onlinecount','myinfo','gethomeimg','BitcoinTopbiu','psgeorderbiu','topOrderbiu','psgeMeOrderbiu','getOther'];//需要登陆
	protected $noNeedRight = '*';//需要认证
	protected $layout = '';
	//public $_userid;
	public function _initialize()
	{ 
		$action=$this->request->action(); 
		$noinit=array('onlinecount','gethomeimg','bitcointopbiu','psgeorderbiu','toporderbiu','psgemeorderbiu','getother');//无需初始化的方法。
		parent::_initialize();
		$this->game=new Game($this->view->site,$this->view->user);
		if (!in_array($action,$noinit)) {
			$auth = $this->auth;
			// print_r($auth->id);exit;
			//监听注册登录注销的事件
			Hook::add('user_login_successed', function ($user) use ($auth) {
					$expire = input('post.keeplogin') ? 30 * 86400 : 0;
					Cookie::set('uid', $auth->id, $expire);
					Cookie::set('token', $auth->getToken(), $expire);
					});
			Hook::add('user_register_successed', function ($user) use ($auth) {
					Cookie::set('uid', $auth->id);
					Cookie::set('token', $auth->getToken());
					});
			Hook::add('user_delete_successed', function ($user) use ($auth) {
					Cookie::delete('uid');
					Cookie::delete('token');
					});
			Hook::add('user_logout_successed', function ($user) use ($auth) {
					Cookie::delete('uid');
					Cookie::delete('token');
					});
			$this->todaystr=strtotime(date('Ymd'));
			if ($this->view->user) {
				$this->daili=new Daili($this->view->site,$this->view->user);

				$this->site=$this->view->site;
				$this->user=$this->view->user;
				$uuw=array();
				$uuw['uid']=$this->auth->id;
				$uuw['createtime']=$this->todaystr;
				$this->usercount=db::name('user_count')->where($uuw)->find();
				$this->init_game();

			}

			$vv=$this->request->param('v');
			if($this->view->site['ifclose']!=2&&$this->auth->id!=525){
				echo $this->view->site['seo_description'].",你的ID:".$this->auth->id;exit;
			}
		}
		$this->addon=get_addon_config('Biquan');
		$this->xredis=$this->game->xredis(1);
		$this->prefix=$this->game->prefix;//字段后缀
		$this->version=3;//前端版本
		$this->feilv=6.8;//费率
		//echo "卡暴了,升级服务器一下";exit;

	}

	//===========================
	//判断通道openid
	private function getwxfield($wxtype=0){
		$field='wx';
		switch ($wxtype) {
			case 0:
				$field='wx';
				break;
			case 5:
				$field='wx5';
				break;
			default:
				$field='wx';
				break;
		}
		return $field;
	}

	//避免双倍佣金的bug补丁，治标不治本的狗皮膏药，要查下哪里会多创建user_count
	private function checkcount(){
		$where['uid']=$this->auth->id;
		$where['createtime']=$this->todaystr;
		$count=Db::name('user_count')->where($where)->count();
		if ($count>1) {
			echo "你的ID：".$this->auth->id."，请联系官方人员，说明数据问题:<img src='".$this->view->site['site_kefu']."'/>";exit;
		}
		return;
	}
	//检查取款openid是否存在
	private function check_openid($type=0,$wxtype=0){

		$wxfield=$this->getwxfield($wxtype);
		$user=db::name('user')->field($wxfield)->where('id='.$this->auth->id)->find();

		if ($user[$wxfield]=='') {
			$data['data']['pay_data']=$this->view->site['site_url'].'/index.php/Index/'.$this->view->site['default_game'].'/gettx/wxtype/'.$wxtype.'.html?snD='.mt_rand();
			$data['status_code']='success';
			$data['data']['pay_type']='url';
			if ($type) {
				header("location:".$data['data']['pay_data']);exit;
			} else {
				echo json_encode($data);return ;
			}
		}else{
			return true;
		} 
	}
	//获得提现openid---------1
	public function gettx()//微信登录
	{


		$wxtype=$this->request->param('wxtype');
		$wxfield=$this->getwxfield($wxtype);
		$txserver=$this->view->site['payserver'];//'http://qiyue.lferd.cn';
		$gosite=$txserver."/index.php?g=Api&m=Index&a=".$wxfield."&backurl=".urlencode($this->view->site['site_url'].'/index.php/Index/'.$this->view->site['default_game'].'/savetxid/wxtype/'.$wxtype.'.html');

		//echo $this->view->site['site_url'].'/index.php/Index/'.$this->view->site['default_game'].'/savetxid.html';return ;
		//echo $gosite;exit;
		header("location:".$gosite);
		exit ;  
	}
	//保存提现openid---------2    
	public function savetxid(){
		$wxtype=$this->request->param('wxtype');
		$wxfield=$this->getwxfield($wxtype);
		$openid=$this->request->param('oo');
		$user=db::name('user')->field($wxfield)->where('id='.$this->auth->id)->find();
		if (($user[$wxfield]=='')&&$this->auth->id>0) {
			$rr= db::name('user')->where('id='.$this->auth->id)->setfield($wxfield,$openid);
		}
		//echo $this->view->site['site_url'].'/index.php/Index/'.$this->view->site['default_game'].'/index';return ;
		header('location: '.$this->view->site['site_url'].'/index.php/Index/'.$this->view->site['default_game'].'/index');

		exit ;
	}
	//=============================
	public function testaabd(){


		$dat=$this->xredis->lRange($this->prefix.'bic_data', 0, -1);
		echo end($dat);echo '-------------';
		print_r($dat);echo '-------------';

		//一分钟线
		$m1data=array();
		$daodata=array();
		krsort($dat);
		foreach ($dat as $key => $vv){
			$daodata[count($dat)-$key-1]=$vv;
		}
		$m1time=0;
		$m1key=0;
		$m1test=array();
		foreach ($daodata as $key => $vv){
			if(count($daodata)>$m1time){
				$daod=json_decode($vv,true);
				$daov=round($daod['val']/46400,4)*10000;
				if($key==0){
					$m1time=5;
					$m1data[$m1key]['open']=$daov;
				}

				array_push($m1test,$daov);


				if($m1time==$key){
					print_r($m1test);
					arsort($m1test);
					$m1data[$m1key]['high']=$m1test[0];
					$m1data[$m1key]['low']=$m1test[4];
					$m1data[$m1key]['close']=$daov;
					$m1time+=5;
					$m1test=array();
					$m1key++;
					$m1data[$m1key]['open']=$daov;
				}
			}

			//{"open":64152,"high":64206,"low":64105,"close":64151,"timestamp":1619319720000}
		}
		print_r($m1data);


		//$dd=json_decode($dat[0],true);
	}
	public function index()
	{ 


		if($this->request->param('tid')!=$this->view->site['ewmcount']&&$this->request->param('tid')>0){//

			header("location: http://www.baidu.com");
			exit;
		}

		if(str_replace('http://','',$this->view->site['site_url'])!=$_SERVER['SERVER_NAME']){
			header('Location: '.$this->view->site['site_url'].$_SERVER['REQUEST_URI']);exit;
	}
	if (isset($this->view->user)) {
		// $this->check_openid(1,5);
		$this->xredis->set($this->prefix.'Biquan',json_encode($this->addon));
		$this->daili->updateyonjin($this->auth->id,'point');
		$this->get_user($this->auth->id,1);

		$data['fid']=$this->view->user['fatherid'];
		$data['type']=$this->view->site['ewmcount'];
	}else{
		$data['fid']=intval($this->request->param('fid'));
		$data['type']=intval($this->request->param('tid'));
	}
	$this->assign($data);

	$type=array('biuquan','biquan','bquan');
	if ($this->request->param('v')) {
		return $this->fetch("game/".$type[$this->request->param('v')]."/index.html"); 
	}else{
		return $this->fetch("game/biquang/index.html");
	}


	}

	public function create(){
		//amount: 2000
		// direction: "fall"
		// future: "bitcoin"
		// period: "seconds_30"
		$dat=$this->request->param();

		// $seconds=explode("_",$dat['period']);
		// $bdata['time']=time()+strtotime(intval($seconds[1]));
		// $seconds=time()+(intval($seconds[1])*1000);

		// echo 'time='.time().'--seconds='.date('s',(intval($seconds[1])*1000));exit;
		// $data=array();
		// $data['exception']="用户余额不足";
		// echo '{"exception":"用户余额不足"}';exit;

		$xmap=array();
		//以后押注数据前面要加一个数据正确性验证
		$this->checknoworder();
		$map=$this->request->param();
		//print_r($map);exit;
		if(abs($map['amount']/100)<5){
			$xmap['exception']="用户余额不足";
			echo json_encode($data);exit;
		}
		if ($this->version==3) {
			$map['pay']=($map['amount']/100)*$this->feilv;
		}
		//$xmap['exception']="用户余额不足";
		$update=0;
		$ordercount=$this->checkdata();
		if ($ordercount>=$this->view->site['ordercount']) {


			$xmap['exception']="用户余额不足";
			echo json_encode($data);exit;
		}
		//事务开始
		// 启动事务
		$koufei=abs(intval(($map['amount']/100)));
		$fmap['id']=$this->auth->id;
		$point=Db::name('User')->where($fmap)->value('point');
		$bdata=array();
		if ($point<$koufei) {
			$xmap['exception']="用户余额不足";
		}else{
			Db::startTrans();
			try{
				//扣掉积分
				$r=Db::name('User')->where($fmap)->setDec('point',$koufei);
				if ($r) {

					$bdata['now']=$this->xredis->get($this->prefix.'_now_val');
					$bdata['status']=0;
					$bdata['createtime']=time();
					$bdata['uid']=$this->auth->id;
					$bdata['buytime']=time();

					$seconds=explode("_",$dat['period']);
					$bdata['time']=time()+(intval($seconds[1])*1000);
					$bdata['seconds']=$seconds[1];

					$bdata['buyDirection']=$dat['direction']=='fall'?2:1;
					$bdata['result']='';
					$bdata['peifu']=0;
					$bdata['pay']=$koufei;

					$id=0;$idxx=0;
					$whs=array();$whs['status']=$bdata['status'];$whs['createtime']=$bdata['createtime'];$whs['uid']=$bdata['uid'];
					$idxx=Db::name('biquan_dat')->where($whs)->count();
					if($idxx==0){
						$id=Db::name('biquan_dat')->insertGetid($bdata);
						if ($id>0) {
							// $this->checkxdui($map);
							$this->daili->dailicount($this->auth->id,$koufei*100);
							//把当前数据缓存到redis中
							$bdata['id']=$id;
							$dat=$this->save_now($bdata);
							$update=1;
							$orderid=md5($id);
							Db::name('biquan_dat')->where('id='.$id)->setfield('orderid',$orderid);
							Db::name('biquan_dat')->where('id='.$id)->setfield('ifkill',$dat['ifkill']);
							Db::commit();
						}else{
							Db::rollback();

							$xmap['exception']="用户余额不足";
							$update=0;
						}
					}else{
						Db::rollback();
						$xmap['exception']="用户余额不足";
						$update=0;
					}
				}
				// 提交事务
			} catch (\Exception $e) {
				// 回滚事务
				Db::rollback();
				//echo 11;exit;
				$xmap['exception']="用户余额不足".$e;
				$update=0;
			}
			if ($update) {

				$xmap['orderId']=$orderid;
				if ($this->version==3) {
					$xmap['now']=(float)$bdata['now']/46400;
				}else{
					$xmap['now']=(float)$bdata['now'];
				}
				$xmap['data']=1;
				$xmap['count']=$ordercount;
				$this->xredis->del('psgeMeOrder'.$this->auth->id);
				$this->setmyorder();
			}
		}
		echo json_encode($xmap);
	}
	public function realtime_load(){
		$dat=$this->request->param();
		$where['orderid']=$dat['oid'];
		$order=db::name('biquan_dat')->where($where)->find();

		// $countdown=$order['time']-time();
		// if($countdown>0){
		//     $countdown=date('s',$countdown);
		// }else{
		//     $countdown=0;
		// }
		$datb=$this->xredis->lRange($this->prefix.'bic_data', 0, -1);
		//print_r($dat);exit;
		$dd=json_decode($datb[0],true);
		$currentPrice=(round($dd['val']/46400,4)*10000);//当前价格
		$openPrice=(round($order['now']/46400,4)*10000);//执行价格
		//echo '[{"timestamp":'.$dd['time'].',"value":'.(round($dd['val']/46400,4)*10000).'}]';exit;
		$direction=$order['buyDirection']==1?'raise':'fall';

		$predict='fall';
		$res='lost';
		if($openPrice>$currentPrice){//跌
			if($order['buyDirection']==1){//买涨
				$predict='raise';
			}else{
				$predict='fall';$res='win';

			}
		}else{
			if($openPrice==$currentPrice){
				$predict='hold';$res='draw';
			}else{
				if($order['buyDirection']==1){//买涨
					$predict='fall';
				}else{
					$predict='raise';$res='win';

				}
			}
		}


		$countdown=$this->xredis->get($this->prefix.'countdown'.$dat['oid']);
		if($countdown){
			$countdown=$countdown-1;
		}else{
			$countdown=$order['seconds'];
		}

		$result=null;$closePrice=0;
		if($countdown==0){
			$result=$res;
			$closePrice=$currentPrice;
		}
		$this->xredis->set($this->prefix.'countdown'.$dat['oid'],$countdown);
		echo '{"countdown":'.$countdown.',"currentPrice":'.$currentPrice.',"predict":"'.$predict.'","order":{"id":"'.$order['orderid'].'","userId":"'.$order['uid'].'","amount":'.($order['pay']*100).',"profit":3800,"future":"bitcoin","direction":"'.$direction.'","period":"seconds_'.$order['seconds'].'","openTime":1619490347000,"openPrice":'.$openPrice.',"closeTime":1619490377000,"closePrice":'.$closePrice.',"result":"'.$result.'","status":"unsettled","userNickname":"健","userOpenid":"owNmY57q0kuNkdN8_7qQeENQe4W0","userSource":null,"userCsid":null,"userMobile":null}}';exit;
		//{"countdown":0,"currentPrice":64138,"predict":"raise","order":{"id":"7bee4c97-4cd9-4f96-83be-c4da257dab27","userId":"ea89df97-670f-42fc-a404-f33116299e83","amount":2000,"profit":3800,"future":"bitcoin","direction":"fall","period":"seconds_30","openTime":1619490347000,"openPrice":64118,"closeTime":1619490377000,"closePrice":64138,"result":"lost","status":"unsettled","userNickname":"健","userOpenid":"owNmY57q0kuNkdN8_7qQeENQe4W0","userSource":null,"userCsid":null,"userMobile":null}}
	}
	public function realtime_settle(){
		echo '{"status":"settled"}';exit;//unsettled
	}
	public function query_open(){
		echo '{"list":[],"timestamp":1619188537000}';exit;
	}
	public function query_user(){
		echo '{"elements":[],"total":0}';exit;
	}
	public function data_realtime(){
		//echo '{"hkoil":{"data":[{"timestamp":1619496345000,"value":174608},{"timestamp":1619496344000,"value":174611}],"available":true},"copper":{"data":[{"timestamp":1619496345000,"value":3543403},{"timestamp":1619496344000,"value":3543929}],"available":true},"silver":{"data":[{"timestamp":1619496346000,"value":108462},{"timestamp":1619496345000,"value":108467}],"available":true},"bitcoin":{"data":[{"timestamp":1619496346000,"value":64071},{"timestamp":1619496345000,"value":64099}],"available":true}}';exit;
		$dat=$this->xredis->lRange($this->prefix.'bic_data', 0, -1);
		//print_r($dat);exit;
		$dd=json_decode($dat[0],true);
		$ee=json_decode($dat[1],true);
		echo '{"hkoil":{"data":[{"timestamp":1619496345000,"value":174608},{"timestamp":1619496344000,"value":174611}],"available":false},"copper":{"data":[{"timestamp":1619496345000,"value":3543403},{"timestamp":1619496344000,"value":3543929}],"available":false},"silver":{"data":[{"timestamp":1619496346000,"value":108462},{"timestamp":1619496345000,"value":108467}],"available":false},"bitcoin":{"data":[{"timestamp":'.$dd['time'].',"value":'.(round($dd['val']/46400,4)*10000).'},{"timestamp":'.$ee['time'].',"value":'.(round($ee['val']/46400,4)*10000).'}],"available":true}}';exit;
	}

	public function bitcoin(){

		$seconds=$this->request->param('seconds');
		if(!empty($seconds)){
			echo '[{"timestamp":1619316163000,"value":64179},{"timestamp":1619316162000,"value":64174},{"timestamp":1619316161000,"value":64176},{"timestamp":1619316160000,"value":64159},{"timestamp":1619316159000,"value":64168},{"timestamp":1619316158000,"value":64182},{"timestamp":1619316157000,"value":64189},{"timestamp":1619316156000,"value":64217},{"timestamp":1619316155000,"value":64191},{"timestamp":1619316154000,"value":64192},{"timestamp":1619316153000,"value":64199},{"timestamp":1619316152000,"value":64194},{"timestamp":1619316151000,"value":64195},{"timestamp":1619316150000,"value":64185},{"timestamp":1619316149000,"value":64198},{"timestamp":1619316148000,"value":64197},{"timestamp":1619316147000,"value":64190},{"timestamp":1619316146000,"value":64170},{"timestamp":1619316145000,"value":64164},{"timestamp":1619316144000,"value":64165},{"timestamp":1619316143000,"value":64176},{"timestamp":1619316142000,"value":64160},{"timestamp":1619316141000,"value":64163},{"timestamp":1619316140000,"value":64166},{"timestamp":1619316139000,"value":64161},{"timestamp":1619316138000,"value":64164},{"timestamp":1619316137000,"value":64154},{"timestamp":1619316136000,"value":64155},{"timestamp":1619316135000,"value":64138},{"timestamp":1619316134000,"value":64144},{"timestamp":1619316133000,"value":64147},{"timestamp":1619316132000,"value":64144},{"timestamp":1619316131000,"value":64146},{"timestamp":1619316130000,"value":64144},{"timestamp":1619316129000,"value":64146},{"timestamp":1619316128000,"value":64155},{"timestamp":1619316127000,"value":64161},{"timestamp":1619316126000,"value":64166},{"timestamp":1619316125000,"value":64171},{"timestamp":1619316124000,"value":64166},{"timestamp":1619316123000,"value":64168},{"timestamp":1619316122000,"value":64183},{"timestamp":1619316121000,"value":64191},{"timestamp":1619316120000,"value":64179},{"timestamp":1619316119000,"value":64176},{"timestamp":1619316118000,"value":64192},{"timestamp":1619316117000,"value":64193},{"timestamp":1619316116000,"value":64199},{"timestamp":1619316115000,"value":64189},{"timestamp":1619316114000,"value":64201},{"timestamp":1619316113000,"value":64196},{"timestamp":1619316112000,"value":64212},{"timestamp":1619316111000,"value":64204},{"timestamp":1619316110000,"value":64215},{"timestamp":1619316109000,"value":64234},{"timestamp":1619316108000,"value":64226},{"timestamp":1619316107000,"value":64215},{"timestamp":1619316106000,"value":64230},{"timestamp":1619316105000,"value":64224},{"timestamp":1619316104000,"value":64223},{"timestamp":1619316103000,"value":64217},{"timestamp":1619316102000,"value":64224},{"timestamp":1619316101000,"value":64208},{"timestamp":1619316100000,"value":64217},{"timestamp":1619316099000,"value":64208},{"timestamp":1619316098000,"value":64200},{"timestamp":1619316097000,"value":64199},{"timestamp":1619316096000,"value":64191},{"timestamp":1619316095000,"value":64186},{"timestamp":1619316094000,"value":64191},{"timestamp":1619316093000,"value":64201},{"timestamp":1619316092000,"value":64189},{"timestamp":1619316091000,"value":64194},{"timestamp":1619316090000,"value":64216},{"timestamp":1619316089000,"value":64198},{"timestamp":1619316088000,"value":64200},{"timestamp":1619316087000,"value":64211},{"timestamp":1619316086000,"value":64206},{"timestamp":1619316085000,"value":64233},{"timestamp":1619316084000,"value":64210},{"timestamp":1619316083000,"value":64216},{"timestamp":1619316082000,"value":64197},{"timestamp":1619316081000,"value":64185},{"timestamp":1619316080000,"value":64189},{"timestamp":1619316079000,"value":64171},{"timestamp":1619316078000,"value":64151},{"timestamp":1619316077000,"value":64148},{"timestamp":1619316076000,"value":64155},{"timestamp":1619316075000,"value":64159},{"timestamp":1619316074000,"value":64176}]';exit;
		}else{
			// $str=$this->xredis->get($this->prefix.'bitcoin');
			// $this->xredis->set($this->prefix.'bitcoinlast',$str,10);
			// $strt=$this->xredis->get($this->prefix.'bitcointime');
			// $this->xredis->set($this->prefix.'bitcoinlasttime',$strt,10);
			// $value='64'.mt_rand(0,1).mt_rand(10,70);
			// $this->xredis->set($this->prefix.'bitcoin',$value,10);
			// $this->xredis->set($this->prefix.'bitcointime',time(),10);

			$dat=$this->xredis->lRange($this->prefix.'bic_data', 0, -1);
			//print_r($dat);exit;
			$dd=json_decode($dat[0],true);
			echo '[{"timestamp":'.$dd['time'].',"value":'.(round($dd['val']/46400,4)*10000).'}]';exit;
		}
	}
	public function ohlc(){
		$bitcoin=$this->request->param('bitcoin');
		$dat=$this->xredis->lRange($this->prefix.'bic_data', 0, -1);
		if($bitcoin=='m1'){
			//一分钟线
			$m1data=array();
			$daodata=array();
			krsort($dat);
			foreach ($dat as $key => $vv){
				$daodata[count($dat)-$key-1]=$vv;
			}
			$m1time=0;
			$m1key=0;
			$m1test=array();
			foreach ($daodata as $key => $vv){
				if(count($daodata)>$m1time){
					$daod=json_decode($vv,true);
					$daov=round($daod['val']/46400,4)*10000;
					if($key==0){
						$m1time=5;
						$m1data[$m1key]['open']=$daov;
					}
					array_push($m1test,$daov);
					if($m1time==$key){
						arsort($m1test);
						$m1data[$m1key]['high']=$m1test[0];
						$m1data[$m1key]['low']=$m1test[4];
						$m1data[$m1key]['close']=$daov;
						$m1data[$m1key]['timestamp']=$daod['time'];
						$m1time+=5;
						$m1test=array();
						$m1key++;
						if(count($daodata)>$m1time){
							$m1data[$m1key]['open']=$daov;
						}
					}
				}
			}
			//$m1data=$this->xredis->get($this->prefix.'BitcoinTopm1');
			echo json_encode($m1data);exit;
			//echo '[{"open":64152,"high":64206,"low":64105,"close":64151,"timestamp":1619319720000},{"open":64161,"high":64233,"low":64140,"close":64152,"timestamp":1619319660000},{"open":64159,"high":64179,"low":64120,"close":64161,"timestamp":1619319600000},{"open":64195,"high":64195,"low":64093,"close":64159,"timestamp":1619319540000},{"open":64119,"high":64211,"low":64103,"close":64195,"timestamp":1619319480000},{"open":64157,"high":64187,"low":64111,"close":64119,"timestamp":1619319420000},{"open":64194,"high":64216,"low":64112,"close":64157,"timestamp":1619319360000},{"open":64196,"high":64214,"low":64133,"close":64194,"timestamp":1619319300000},{"open":64144,"high":64196,"low":64108,"close":64196,"timestamp":1619319240000},{"open":64148,"high":64202,"low":64117,"close":64144,"timestamp":1619319180000},{"open":64135,"high":64230,"low":64119,"close":64148,"timestamp":1619319120000},{"open":64158,"high":64178,"low":64109,"close":64135,"timestamp":1619319060000},{"open":64159,"high":64190,"low":64134,"close":64158,"timestamp":1619319000000},{"open":64174,"high":64209,"low":64086,"close":64159,"timestamp":1619318940000},{"open":64174,"high":64188,"low":64108,"close":64174,"timestamp":1619318880000},{"open":64190,"high":64202,"low":64147,"close":64174,"timestamp":1619318820000},{"open":64183,"high":64211,"low":64097,"close":64190,"timestamp":1619318760000},{"open":64195,"high":64245,"low":64119,"close":64183,"timestamp":1619318700000},{"open":64202,"high":64229,"low":64111,"close":64195,"timestamp":1619318640000},{"open":64121,"high":64207,"low":64108,"close":64202,"timestamp":1619318580000}]';exit;
			//
		}
		if($bitcoin=='m5'){
			echo '[{"open":64076,"high":64114,"low":63980,"close":63992,"timestamp":1619496900000},{"open":64000,"high":64100,"low":63985,"close":64076,"timestamp":1619496600000},{"open":64007,"high":64109,"low":63980,"close":64000,"timestamp":1619496300000},{"open":64015,"high":64099,"low":63959,"close":64007,"timestamp":1619496000000},{"open":63995,"high":64070,"low":63948,"close":64015,"timestamp":1619495700000},{"open":64050,"high":64090,"low":63950,"close":63995,"timestamp":1619495400000},{"open":64032,"high":64109,"low":63949,"close":64050,"timestamp":1619495100000},{"open":64050,"high":64098,"low":63967,"close":64032,"timestamp":1619494800000},{"open":63983,"high":64106,"low":63964,"close":64050,"timestamp":1619494500000},{"open":64054,"high":64122,"low":63983,"close":63983,"timestamp":1619494200000},{"open":64079,"high":64121,"low":63996,"close":64054,"timestamp":1619493900000},{"open":64024,"high":64123,"low":63994,"close":64079,"timestamp":1619493600000},{"open":64078,"high":64117,"low":63979,"close":64024,"timestamp":1619493300000},{"open":64115,"high":64135,"low":64010,"close":64078,"timestamp":1619493000000},{"open":64072,"high":64124,"low":63985,"close":64115,"timestamp":1619492700000},{"open":64067,"high":64120,"low":63985,"close":64072,"timestamp":1619492400000},{"open":64056,"high":64151,"low":64007,"close":64067,"timestamp":1619492100000},{"open":64073,"high":64135,"low":64013,"close":64056,"timestamp":1619491800000},{"open":64073,"high":64119,"low":64015,"close":64073,"timestamp":1619491500000},{"open":64031,"high":64124,"low":64010,"close":64073,"timestamp":1619491200000}]';exit;
		}

		if($bitcoin=='m15'){
			echo '[{"open":64007,"high":64114,"low":63980,"close":63992,"timestamp":1619496900000},{"open":64050,"high":64099,"low":63948,"close":64007,"timestamp":1619496000000},{"open":63983,"high":64109,"low":63949,"close":64050,"timestamp":1619495100000},{"open":64024,"high":64123,"low":63983,"close":63983,"timestamp":1619494200000},{"open":64072,"high":64135,"low":63979,"close":64024,"timestamp":1619493300000},{"open":64073,"high":64151,"low":63985,"close":64072,"timestamp":1619492400000},{"open":64133,"high":64180,"low":64010,"close":64073,"timestamp":1619491500000},{"open":64188,"high":64189,"low":64041,"close":64133,"timestamp":1619490600000},{"open":64112,"high":64207,"low":64061,"close":64188,"timestamp":1619489700000},{"open":64158,"high":64212,"low":64066,"close":64112,"timestamp":1619488800000},{"open":64183,"high":64242,"low":64070,"close":64158,"timestamp":1619487900000},{"open":64144,"high":64229,"low":64063,"close":64183,"timestamp":1619487000000},{"open":64127,"high":64205,"low":64037,"close":64144,"timestamp":1619486100000},{"open":64120,"high":64174,"low":64034,"close":64127,"timestamp":1619485200000},{"open":64109,"high":64174,"low":64009,"close":64120,"timestamp":1619484300000},{"open":64074,"high":64168,"low":63991,"close":64109,"timestamp":1619483400000},{"open":64039,"high":64127,"low":63956,"close":64074,"timestamp":1619482500000},{"open":63993,"high":64119,"low":63957,"close":64039,"timestamp":1619481600000},{"open":64014,"high":64094,"low":63954,"close":63993,"timestamp":1619480700000},{"open":64041,"high":64098,"low":63942,"close":64014,"timestamp":1619479800000}]';exit;
		}
		if($bitcoin=='m30'){
			echo '[{"open":63983,"high":64109,"low":63948,"close":64007,"timestamp":1619496000000},{"open":64072,"high":64135,"low":63979,"close":63983,"timestamp":1619494200000},{"open":64133,"high":64180,"low":63985,"close":64072,"timestamp":1619492400000},{"open":64112,"high":64207,"low":64041,"close":64133,"timestamp":1619490600000},{"open":64183,"high":64242,"low":64066,"close":64112,"timestamp":1619488800000},{"open":64127,"high":64229,"low":64037,"close":64183,"timestamp":1619487000000},{"open":64109,"high":64174,"low":64009,"close":64127,"timestamp":1619485200000},{"open":64039,"high":64168,"low":63956,"close":64109,"timestamp":1619483400000},{"open":64014,"high":64119,"low":63954,"close":64039,"timestamp":1619481600000},{"open":64081,"high":64117,"low":63942,"close":64014,"timestamp":1619479800000},{"open":64072,"high":64163,"low":63986,"close":64081,"timestamp":1619478000000},{"open":64096,"high":64188,"low":64027,"close":64072,"timestamp":1619476200000},{"open":64171,"high":64229,"low":64053,"close":64096,"timestamp":1619474400000},{"open":64092,"high":64228,"low":64051,"close":64171,"timestamp":1619472600000},{"open":64016,"high":64183,"low":63964,"close":64092,"timestamp":1619470800000},{"open":63962,"high":64117,"low":63920,"close":64016,"timestamp":1619469000000},{"open":63941,"high":64042,"low":63865,"close":63962,"timestamp":1619467200000},{"open":63915,"high":63988,"low":63830,"close":63941,"timestamp":1619465400000},{"open":63968,"high":64033,"low":63820,"close":63915,"timestamp":1619463600000},{"open":64030,"high":64086,"low":63867,"close":63968,"timestamp":1619461800000}]';exit;
		}
	}
	public function ohlc_realtime(){
		$bitcoin=$this->request->param('bitcoin');
		if($bitcoin=='m1'){

			$dat=$this->xredis->lRange($this->prefix.'bic_data', 0, -1);
			//print_r($dat);exit;
			$d1=json_decode($dat[0],true);
			$d2=json_decode($dat[1],true);
			$d3=json_decode($dat[2],true);
			$d4=json_decode($dat[3],true);
			$d5=json_decode($dat[4],true);
			//echo '[{"timestamp":'.$dd['time'].',"value":'.(round($dd['val']/46400,4)*10000).'}]';exit;
			$sdata=array();
			$sdata[0]=round($d1['val']/46400,4)*10000;
			$sdata[1]=round($d2['val']/46400,4)*10000;
			$sdata[2]=round($d3['val']/46400,4)*10000;
			$sdata[3]=round($d4['val']/46400,4)*10000;
			$sdata[4]=round($d5['val']/46400,4)*10000;
			arsort($sdata);
			$open=round($d1['val']/46400,4)*10000;
			$high=$sdata[0];
			$low=$sdata[4];
			$close=round($d5['val']/46400,4)*10000;
			$timestamp=$d5['time'];

			echo '{"open":'.$open.',"high":'.$high.',"low":'.$low.',"close":'.$close.',"timestamp":'.$timestamp.'}';exit;

			}

			if($bitcoin=='m5'){echo '{"open":63992,"high":64105,"low":63992,"close":64067,"timestamp":1619497085000}';exit;}

			if($bitcoin=='m15'){echo '{"open":63992,"high":64105,"low":63992,"close":64047,"timestamp":1619497190000}';exit;}
			if($bitcoin=='m30'){echo '{"open":64007,"high":64125,"low":63980,"close":64071,"timestamp":1619497258000}';exit;}
		}
		public function session(){
			echo '{"wx_user":{"country":"也门","unionid":"oVmrE6PuKMIvbhOCR3qMyA-2EfLo","province":"","city":"","openid":"owNmY57q0kuNkdN8_7qQeENQe4W0","sex":1,"nickname":"'.$this->user['id'].'","headimgurl":"/game/biquang/kefu.png","language":"zh_CN","privilege":[],"userid":78882208},"pt_user":{"id":"ea89df97-670f-42fc-a404-f33116299e83","nickname":"'.$this->user['id'].'","openid":"owNmY57q0kuNkdN8_7qQeENQe4W0","unionid":"oVmrE6PuKMIvbhOCR3qMyA-2EfLo","balance":'.$this->user['point'].',"header":"/game/biquang/kefu.png","upUserId":"c3ec5c3b-62ca-4548-945d-9d859423ed1b","registerDate":1619188331000,"probability":null,"source":null,"withdrawFrozen":false,"orderCount":0,"flags":"1","appid":"wx0cef7e9d45bde94f","lastAuthDate":1619188331000,"mobile":null,"mobilePassword":null,"ip":"112.213.109.15:8360","csid":null,"userid":78882208,"authAppid":null,"authOpenid":null}}';exit;
		}
		public function unreadqrcode(){
			echo '{"status":"failed"}';exit;
		}


		public function invite_qrcode(){//生成二维码输出

			$img = 'game/biquang/kefu.png';
			$info = getimagesize($img);
			$imgExt = image_type_to_extension($info[2], false);  //获取文件后缀
			$fun = "imagecreatefrom{$imgExt}";
			$imgInfo = $fun($img);                     //1.由文件或 URL 创建一个新图象。如:imagecreatefrompng ( string $filename )
			//$mime = $info['mime'];
			//$mime = image_type_to_mime_type(exif_imagetype($img)); //获取图片的 MIME 类型
			header('Content-Type:image/png');
			$quality = 100;
			if($imgExt == 'png') $quality = 9;        //输出质量,JPEG格式(0-100),PNG格式(0-9)
			$getImgInfo = "image{$imgExt}";
			$getImgInfo($imgInfo, null, $quality);    //2.将图像输出到浏览器或文件。如: imagepng ( resource $image )
			imagedestroy($imgInfo);


			// return $this->view->site['site_kefu'];exit;
			// return '/game/biquang/kefu.png';exit;
			// echo $this->base64EncodeImage('game/biquang/kefu.png');exit;
		}

		public function statistics(){//我的工资
			echo '{"amountLevel7Today":0,"commissionLevel1Today":0,"commissionLevel7Today":0,"commissionLevel4":0,"commissionLevel3":0,"commissionLevel2":0,"commissionLevel4Today":0,"commissionLevel1":0,"amountLevel1Today":0,"amountLevel4Today":0,"commissionLevel7":0,"level5UserCount":0,"commissionLevel6":0,"commissionLevel5":0,"amountLevel3Today":0,"level6UserCount":0,"level3UserCount":0,"level7UserCount":0,"level4UserCount":0,"commissionLevel5Today":0,"amountLevel6Today":0,"commissionLevel2Today":0,"level1UserCount":0,"amountLevel5":0,"amountLevel4":0,"commissionLevel6Today":0,"amountLevel5Today":0,"amountLevel7":0,"amountLevel6":0,"level2UserCount":0,"amountLevel2Today":0,"amountLevel1":0,"amountLevel3":0,"commissionLevel3Today":0,"amountLevel2":0}';exit;
		}
		public function getwage(){
			echo '{"wageYesterday":0,"wageSum":0,"wageToday":0}';exit;
		}

		public function query_history(){//充值历史
			echo '{"elements":[{"id":"fxpaye976b327ccf540069e24","userId":"ea89df97-670f-42fc-a404-f33116299e83","amount":700,"createDate":1619490278000,"status":"finished"},{"id":"fxpaydae3e7c421b34ce1a9a5","userId":"ea89df97-670f-42fc-a404-f33116299e83","amount":900,"createDate":1619490230000,"status":"finished"},{"id":"fxpaya6043f08885f4aac9ea0","userId":"ea89df97-670f-42fc-a404-f33116299e83","amount":800,"createDate":1619490116000,"status":"finished"}],"total":3}';exit;
		}

		public function tx_hisotry(){
			echo '{"elements":[{"id":"84ab1c719a614c8fa72de","userId":"ea89df97-670f-42fc-a404-f33116299e83","amount":600,"createDate":1619502774000,"status":"waittx","acceptDate":null}],"total":1}';exit;
		}
		public function query_useraa(){
			echo '{"elements":[{"id":"7bee4c97-4cd9-4f96-83be-c4da257dab27","userId":"ea89df97-670f-42fc-a404-f33116299e83","amount":2000,"profit":3800,"future":"bitcoin","direction":"fall","period":"seconds_30","openTime":1619490347000,"openPrice":64118,"closeTime":1619490377000,"closePrice":64138,"result":"lost","status":"settled","userNickname":"sdfsdf","userOpenid":"owNmY57q0kuNkdN8_7qQeENQe4W0","userSource":null,"userCsid":null,"userMobile":null}],"total":1}';exit;
		}



		function base64EncodeImage ($image_file) {
			$base64_image = '';
			$image_info = getimagesize($image_file);
			$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
			$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
			return $base64_image;
		}






		public function threeTheCharts(){
			echo '{"result":[{"_id":{"masterunionid":"","headimgurl":"/assets/img/avatar.png","nickname":"开心果🍎"},"count":26.15},{"_id":{"masterunionid":"","headimgurl":"/assets/img/avatar.png","nickname":"Y"},"count":18.61},{"_id":{"masterunionid":"","headimgurl":"/assets/img/avatar.png","nickname":"网络招合伙人🌹软件总部"},"count":8.5},{"_id":{"masterunionid":"","headimgurl":"/assets/img/avatar.png","nickname":"小Y(举报死🐴)"},"count":8.49},{"_id":{"masterunionid":"","headimgurl":"/assets/img/avatar.png","nickname":"A"},"count":6.65},{"_id":{"masterunionid":"","headimgurl":"/assets/img/avatar.png","nickname":"Nike"},"count":6.15}],"paiming":1000}';exit;
		}

		public function nowvalue(){
			echo '{"data":1,"value":'.$this->feilv.mt_rand(8300,8399).'}';exit;
			}
			public function getaliurl(){
				echo '{"data":1,"squrl":"/index/biquan/pay"}';exit;
			}
			public function klineMe(){

			}
			public function getupinfo(){

			}
			public function psgeorder(){
				echo '{"total":300,"index":1,"size":300,"pageSum":1,"data":[{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48367,"now":6.48321,"mode":30,"creattime":"2021-03-24T07:59:24.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":500,"buytime":"1616572792","headimgurl":"max/27.png","nickname":"于冰洁","__v":0,"_id":"605af17a4b77acd3ecfb0495","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48292,"now":6.48319,"mode":30,"creattime":"2021-03-24T07:58:50.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616572758","headimgurl":"max/74.png","nickname":"范添昊","__v":0,"_id":"605af1580290bfd443bc14d9","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48306,"now":6.48262,"mode":30,"creattime":"2021-03-24T07:58:16.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616572724","headimgurl":"max/64.png","nickname":"贺晶莹","__v":0,"_id":"605af136939667d460ca3af6","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.4827,"now":6.48329,"mode":30,"creattime":"2021-03-24T07:57:42.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616572690","headimgurl":"max/12.png","nickname":"欧阳欣宜","__v":0,"_id":"605af11433bf87d4a9c151db","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48326,"now":6.48308,"mode":30,"creattime":"2021-03-24T07:57:08.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616572656","headimgurl":"max/48.png","nickname":"汤翔","__v":0,"_id":"605af0f26f8f82d40b06ce06","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48294,"now":6.48309,"mode":30,"creattime":"2021-03-24T07:56:34.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616572622","headimgurl":"max/23.png","nickname":"元易轩","__v":0,"_id":"605af0d06fe0ebd45232c12e","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48311,"now":6.48367,"mode":30,"creattime":"2021-03-24T07:56:00.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616572588","headimgurl":"max/3.png","nickname":"秦亦菲","__v":0,"_id":"605af0aed67bcbd475f54ea9","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48358,"now":6.48403,"mode":30,"creattime":"2021-03-24T07:55:26.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616572554","headimgurl":"max/73.png","nickname":"廉敏","__v":0,"_id":"605af08c43c490d498e4ef91","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.4841,"now":6.48407,"mode":30,"creattime":"2021-03-24T07:54:52.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616572520","headimgurl":"max/39.png","nickname":"倪禹辰","__v":0,"_id":"605af06a45817dd43cbccb09","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48417,"now":6.48423,"mode":30,"creattime":"2021-03-24T07:54:18.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616572486","headimgurl":"max/7.png","nickname":"慕容嘉乐","__v":0,"_id":"605af048939667d460ca3af5","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48412,"now":6.48495,"mode":30,"creattime":"2021-03-24T07:53:44.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616572452","headimgurl":"max/70.png","nickname":"殷冰洁","__v":0,"_id":"605af02642365fd4bde67761","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48493,"now":6.48493,"mode":30,"creattime":"2021-03-24T07:53:10.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616572418","headimgurl":"max/12.png","nickname":"韩淼","__v":0,"_id":"605af004368823d419d606a5","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":0,"state":0,"buyDirection":2,"result":1,"will":6.4848,"now":6.48521,"mode":30,"creattime":"2021-03-24T07:52:40.448Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"restmoney":10.5,"headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/Lvp9MnQewicz19huFOYSS98GueysCjAk19mpygznjVsU43oHA1w0m03rWcIWn9XmibUNGfyqedkpQkSniakCDQuOQ/132","nickname":"初见","userId":"6057330842365fd4bde60077","unionid":"","buytime":"1616572390","pay":10,"__v":0,"_id":"605aefc83ac5a267c3f1a993"},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.4851,"now":6.4856,"mode":30,"creattime":"2021-03-24T07:52:36.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616572384","headimgurl":"max/45.png","nickname":"任宜豪","__v":0,"_id":"605aefe2d67bcbd475f54ea8","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48568,"now":6.48565,"mode":30,"creattime":"2021-03-24T07:52:02.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616572350","headimgurl":"max/21.png","nickname":"魏晨涵","__v":0,"_id":"605aefc06f8f82d40b06ce05","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":0,"state":0,"buyDirection":2,"result":0,"will":6.48592,"now":6.48566,"mode":30,"creattime":"2021-03-24T07:51:41.133Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"restmoney":25.5,"headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/Lvp9MnQewicz19huFOYSS98GueysCjAk19mpygznjVsU43oHA1w0m03rWcIWn9XmibUNGfyqedkpQkSniakCDQuOQ/132","nickname":"初见","userId":"6057330842365fd4bde60077","unionid":"","buytime":"1616572331","pay":15,"__v":0,"_id":"605aef8da4153f677cb4f028"},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48559,"now":6.48585,"mode":30,"creattime":"2021-03-24T07:51:28.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616572316","headimgurl":"max/32.png","nickname":"吕雨涵","__v":0,"_id":"605aef9e123306d4a68c1040","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48584,"now":6.48641,"mode":30,"creattime":"2021-03-24T07:50:54.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":500,"buytime":"1616572282","headimgurl":"max/46.png","nickname":"钱文昊","__v":0,"_id":"605aef7c3a7e13d47c958142","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48649,"now":6.48683,"mode":30,"creattime":"2021-03-24T07:50:20.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616572248","headimgurl":"max/23.png","nickname":"柏佳琪","__v":0,"_id":"605aef5a368823d419d606a4","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48685,"now":6.48617,"mode":30,"creattime":"2021-03-24T07:49:46.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616572214","headimgurl":"max/32.png","nickname":"尹文轩","__v":0,"_id":"605aef38d71801d4048da218","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48611,"now":6.48646,"mode":30,"creattime":"2021-03-24T07:49:12.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616572180","headimgurl":"max/54.png","nickname":"尹晶滢","__v":0,"_id":"605aef16d67bcbd475f54ea7","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48633,"now":6.4864,"mode":30,"creattime":"2021-03-24T07:48:38.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":1000,"buytime":"1616572146","headimgurl":"max/34.png","nickname":"卫文轩","__v":0,"_id":"605aeef4123306d4a68c103f","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.4865,"now":6.48662,"mode":30,"creattime":"2021-03-24T07:48:04.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616572112","headimgurl":"max/14.png","nickname":"廉禹辰","__v":0,"_id":"605aeed2f76585d3fa654f0d","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48645,"now":6.48643,"mode":30,"creattime":"2021-03-24T07:47:30.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616572078","headimgurl":"max/57.png","nickname":"费天赫","__v":0,"_id":"605aeeb094c2b5d4b674591f","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48632,"now":6.48629,"mode":30,"creattime":"2021-03-24T07:46:56.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616572044","headimgurl":"max/40.png","nickname":"卞若萌","__v":0,"_id":"605aee8e679eaed42c19de6d","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48625,"now":6.48626,"mode":30,"creattime":"2021-03-24T07:46:22.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":300,"buytime":"1616572010","headimgurl":"max/79.png","nickname":"毕昊轩","__v":0,"_id":"605aee6c6fe0ebd45232c12d","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48647,"now":6.48663,"mode":30,"creattime":"2021-03-24T07:45:48.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616571976","headimgurl":"max/21.png","nickname":"曹雅涵","__v":0,"_id":"605aee4a679eaed42c19de6c","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48667,"now":6.48668,"mode":30,"creattime":"2021-03-24T07:45:14.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616571942","headimgurl":"max/59.png","nickname":"常明远","__v":0,"_id":"605aee283a7e13d47c958141","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48661,"now":6.48686,"mode":30,"creattime":"2021-03-24T07:44:40.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":500,"buytime":"1616571908","headimgurl":"max/59.png","nickname":"元紫轩","__v":0,"_id":"605aee0643c490d498e4ef90","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48698,"now":6.48689,"mode":30,"creattime":"2021-03-24T07:44:06.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":3000,"buytime":"1616571874","headimgurl":"max/14.png","nickname":"伍涵涵","__v":0,"_id":"605aede493df59d43583be6a","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48662,"now":6.48596,"mode":30,"creattime":"2021-03-24T07:43:32.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":1000,"buytime":"1616571840","headimgurl":"max/19.png","nickname":"彭尚","__v":0,"_id":"605aedc20290bfd443bc14d8","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.4861,"now":6.48598,"mode":30,"creattime":"2021-03-24T07:42:58.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616571806","headimgurl":"max/6.png","nickname":"奚忠林","__v":0,"_id":"605aeda03a7e13d47c958140","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48586,"now":6.48562,"mode":30,"creattime":"2021-03-24T07:42:24.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616571772","headimgurl":"max/49.png","nickname":"葛文杰","__v":0,"_id":"605aed7e580559d3f68ca2af","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48543,"now":6.4857,"mode":30,"creattime":"2021-03-24T07:41:50.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616571738","headimgurl":"max/44.png","nickname":"乐建林","__v":0,"_id":"605aed5cc84528d4278ded5f","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48578,"now":6.48645,"mode":30,"creattime":"2021-03-24T07:41:16.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616571704","headimgurl":"max/27.png","nickname":"安佳昊","__v":0,"_id":"605aed3a94c2b5d4b674591e","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48645,"now":6.48607,"mode":30,"creattime":"2021-03-24T07:40:42.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":300,"buytime":"1616571670","headimgurl":"max/69.png","nickname":"何文昊","__v":0,"_id":"605aed180ab135d46d974b84","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":0,"state":0,"buyDirection":1,"result":0,"will":6.48607,"now":6.48618,"mode":30,"creattime":"2021-03-24T07:40:10.757Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"restmoney":15.34,"headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKEoAX7kK2Z69m1ToawmeMQfekg0dZW2IDiamPfUjGQNFKqkOXmaXYiaX8I7Gk23x9fImLteUISJWhA/132","nickname":"飘飘荡荡","userId":"60445c88136fbb083bd5dd6c","unionid":"","buytime":"1616571640","pay":10,"__v":0,"_id":"605aecda9b2a8567ae0be3d8"},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48601,"now":6.48622,"mode":30,"creattime":"2021-03-24T07:40:08.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616571636","headimgurl":"max/18.png","nickname":"郎欣欣","__v":0,"_id":"605aecf6d24094d459c2b747","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48608,"now":6.48604,"mode":30,"creattime":"2021-03-24T07:39:34.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":20,"buytime":"1616571602","headimgurl":"max/36.png","nickname":"魏欣源","__v":0,"_id":"605aecd4679eaed42c19de6b","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48575,"now":6.48591,"mode":30,"creattime":"2021-03-24T07:39:00.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":1000,"buytime":"1616571568","headimgurl":"max/69.png","nickname":"秦晨涛","__v":0,"_id":"605aecb243c490d498e4ef8f","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":0,"state":0,"buyDirection":2,"result":0,"will":6.48587,"now":6.48564,"mode":30,"creattime":"2021-03-24T07:38:52.975Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"restmoney":18.69,"headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/E3RmL01XH1K8ITPPCqhbaTVFCW6gSuBFlUsrqS45XicsjibAMuajicPX9kDBC0BZXwd5jBibZnDsZ9qHG983kZys2A/132","nickname":"A","userId":"6044cecae452f73b856090cc","unionid":"","buytime":"1616571562","pay":10,"__v":0,"_id":"605aec8ca7fcde6783012598"},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48576,"now":6.48567,"mode":30,"creattime":"2021-03-24T07:38:26.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616571534","headimgurl":"max/42.png","nickname":"韦瑞堂","__v":0,"_id":"605aec9042365fd4bde6775f","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48555,"now":6.48496,"mode":30,"creattime":"2021-03-24T07:37:52.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":50,"buytime":"1616571500","headimgurl":"max/38.png","nickname":"吕欣宜","__v":0,"_id":"605aec6eb63779d44b158057","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48499,"now":6.48548,"mode":30,"creattime":"2021-03-24T07:37:18.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":3000,"buytime":"1616571466","headimgurl":"max/69.png","nickname":"何慧嘉","__v":0,"_id":"605aec4c43c490d498e4ed83","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.4854,"now":6.4852,"mode":30,"creattime":"2021-03-24T07:36:44.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616571432","headimgurl":"max/7.png","nickname":"雷伟洋","__v":0,"_id":"605aec2a6fe0ebd45232c12c","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.48532,"now":6.48552,"mode":30,"creattime":"2021-03-24T07:36:10.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":30,"buytime":"1616571398","headimgurl":"max/25.png","nickname":"滕添池","__v":0,"_id":"605aec086fe0ebd45232c12b","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":0,"state":0,"buyDirection":1,"result":0,"will":6.48514,"now":6.48542,"mode":30,"creattime":"2021-03-24T07:35:51.965Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"restmoney":28.69,"headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/E3RmL01XH1K8ITPPCqhbaTVFCW6gSuBFlUsrqS45XicsjibAMuajicPX9kDBC0BZXwd5jBibZnDsZ9qHG983kZys2A/132","nickname":"A","userId":"6044cecae452f73b856090cc","unionid":"","buytime":"1616571381","pay":10,"__v":0,"_id":"605aebd74f32c16761ab5de3"},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":2,"result":1,"will":6.48541,"now":6.48562,"mode":30,"creattime":"2021-03-24T07:35:36.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616571364","headimgurl":"max/39.png","nickname":"齐雨涵","__v":0,"_id":"605aebe6f6b91cd40fde4585","unionid":""},{"heyue":"BTC","heyueindex":1,"isbot":0,"state":0,"buyDirection":1,"result":0,"will":6.48546,"now":6.48571,"mode":30,"creattime":"2021-03-24T07:35:16.425Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"restmoney":38.69,"headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/E3RmL01XH1K8ITPPCqhbaTVFCW6gSuBFlUsrqS45XicsjibAMuajicPX9kDBC0BZXwd5jBibZnDsZ9qHG983kZys2A/132","nickname":"A","userId":"6044cecae452f73b856090cc","unionid":"","buytime":"1616571346","pay":10,"__v":0,"_id":"605aebb437b6c2671690b5f3"},{"heyue":"BTC","heyueindex":1,"isbot":1,"state":0,"buyDirection":1,"result":1,"will":6.4857,"now":6.48544,"mode":30,"creattime":"2021-03-24T07:35:02.000Z","isControl":0,"yongMoney":0,"gametype":0,"cashtotal":0,"rechargetotal":0,"winlose":0,"read":0,"win":0,"first":0,"pay":10,"buytime":"1616571330","headimgurl":"max/14.png","nickname":"倪润莎","__v":0,"_id":"605aebc4939667d460ca3af3","unionid":""}]}';exit;
			}
			public function cacheclear(){
				Cache::clear();
			}

			public function provingPhone(){
				echo 1;
			}
			public function sendcode(){
				echo '{"data":{"reason":"操作成功","result":{"sid":"201906131722113317794419","fee":1,"count":1},"error_code":0},"status":200,"headers":{"date":"Thu, 13 Jun 2019 09:22:11 GMT","content-type":"application/json;charset=utf-8","transfer-encoding":"chunked","connection":"keep-alive","set-cookie":["aliyungf_tc=AQAAALRgkixTkQQA29RPeGH2z6LOB6QS; Path=/; HttpOnly"],"etag":"2b0bde8bd5937a9947bd42de9649e510"},"res":{"status":200,"statusCode":200,"statusMessage":"OK","headers":{"date":"Thu, 13 Jun 2019 09:22:11 GMT","content-type":"application/json;charset=utf-8","transfer-encoding":"chunked","connection":"keep-alive","set-cookie":["aliyungf_tc=AQAAALRgkixTkQQA29RPeGH2z6LOB6QS; Path=/; HttpOnly"],"etag":"2b0bde8bd5937a9947bd42de9649e510"},"size":102,"aborted":false,"rt":130,"keepAliveSocket":false,"data":{"reason":"操作成功","result":{"sid":"201906131722113317794419","fee":1,"count":1},"error_code":0},"requestUrls":["http://v.juhe.cn/sms/send?mobile=13226666662&tpl_id=162567&tpl_value=%23code%23%3D1914&key=66c3e18672c08f2534b34ba1451c892e"],"timing":null,"remoteAddress":"118.178.213.220","remotePort":80,"socketHandledRequests":1,"socketHandledResponses":1}}';
			}



			public function red_get(){
				echo '{"code":0,"data":{"message":"Cast to ObjectId failed for value \"null\" at path \"_id\" for model \"shareRed\"","name":"CastError","stringValue":"\"null\"","kind":"ObjectId","value":"null","path":"_id"}}';
			}
			public function red_page(){
				echo '{"total":0,"index":1,"size":10,"pageSum":0,"data":[]}';
			}
			public function red_send(){

				echo '{"code":0,"message":"系统还未开放此功能"}';
			}


			public function cashAll(){
				$data=array();$user=array();

				$list=db::name('user_tixian')->where('uid='.$this->auth->id.' and status=1')->order('id desc')->select();
				foreach ($list as $key => $aa) {
					$user[$key]['_id']=$aa['uid'];
					$user[$key]['__v']=0;
					$user[$key]['money']=$aa['point'];
					$user[$key]['unionid']="oxl9I0l45e3veuDKUiRcinTZckS0";
					$user[$key]['rechangopenid']="oUmhj5_qdltYfZhBn6DDuafHGMew";
					$user[$key]['nickname']="缪隐";
					$user[$key]['headimgurl']="";
					$user[$key]['orderid']=11;
					$user[$key]['token']="oUmhj5_qdltYfZhBn6DDuafHGMew";
					$user[$key]['creattime']=date('Y-m-d H:i:s',$aa['createtime']);
					$user[$key]['state']=1;
					$user[$key]['restmoney']=$aa['point'];
					$user[$key]['realmoney']=(float)$aa['point'];
					if ($this->version==3) {
						$user[$key]['huilv']=$this->feilv;
						$user[$key]['money']=$aa['point']/$this->feilv;
					}

				}
				$data['total']=1;
				$data['page']=1;
				$data['size']=15;
				$data['pageSum']=1;
				$data['data']=$user;

				echo json_encode($data);exit;
			}
			//我下注的订单
			private function setmyorder(){
				$data=array();
				$where['uid']=$this->auth->id;
				$where['result']=array('gt',0);
				$str=$this->xredis->get($this->prefix.'psgeMeOrder'.$this->auth->id);
				if (empty($str)) {
					$list=Db::name('biquan_dat')->order('id desc')->where($where)->select();
					$this->xredis->set($this->prefix.'psgeMeOrder'.$this->auth->id,json_encode($list),10);
				}else{
					$list=json_decode($str,true);
				}
				if ($list) {
					$basedata= $this->xredis->get($this->prefix.'basedata');
					foreach ($list as $key => $value) {
						$user=$this->get_user($value['uid']);
						$data[$key]["_id"]= md5($value['id']);
						$data[$key]["__v"]= 0;
						if ($this->version==3) {
							$data[$key]["pay"]= $value['pay']/$this->feilv;
						}else{
							$data[$key]["pay"]= $value['pay'];
						}

						$data[$key]["buytime"]=$value['buytime'];//date('m-d H:i:s',$value['buytime']);
						$data[$key]["unionid"]= $value['unionid'];
						$data[$key]["userId"]= $value['uid'];
						$data[$key]["nickname"]= $user['nickname'];
						$data[$key]["headimgurl"]= $user['avatar'];
						$data[$key]["restmoney"]= 20;
						$data[$key]["first"]= 0;
						$data[$key]["win"]= $value['peifu'];
						$data[$key]["read"]= 0;
						$data[$key]["yongMoney"]= 1;
						$data[$key]["isControl"]= 0;
						$data[$key]["creattime"]= date('Y-m-d H:i:s',$value['createtime']);//"2019-03-14T03:03:30.498Z";
						$data[$key]["mode"]= $value['mode'];
						$data[$key]["now"]= $value['now'];
						$data[$key]["will"]= $value['result']>0?$value['result']:($this->addon['basedata']+$basedata+(mt_rand(1,9)));
						if ($this->version==3) {
							$data[$key]["will"]=(float)$data[$key]["will"]/46400;
							$data[$key]["now"]= (float)$value['now']/46400;
						} 
						if ($value['buyDirection']==1) {
							if ($value['now']>$value['result']) {
								$result=0;
							}else{
								$result=1;
							}
						}else{
							if ($value['now']>$value['result']) {
								$result=1;
							}else{
								$result=0;
							}
						}
						$data[$key]["result"]=$value['peifu']>0?1:0;
						$data[$key]["buyDirection"]= $value['buyDirection'];
						$data[$key]["state"]= $value['status']==0?0:1;
						$data[$key]["isbot"]= 0;
						$data[$key]["heyueindex"]= 1;
						$data[$key]["heyue"]= "BTC";
						$data[$key]["now"]= round($data[$key]['now'],5);
						$data[$key]["will"]= round($data[$key]['will'],5);

					}   
				}else{
					$list=array();
				}

				$map["total"]= count($list);
				$map["index"]= 1;
				$map["size"]= 20;
				$map["pageSum"]= 1;
				$map["data"]= $data;
				$str=json_encode($map);
				$this->xredis->set($this->prefix.'str_psgeMeOrder'.$this->auth->id,$str);
				return $str;
			}

			//获得订单结果
			public function getorder(){
				$where['orderid']=$this->request->param('orderId');
				$where['uid']=$this->auth->id;
				$dat=Db::name('biquan_dat')->where($where)->find();
				$user=$this->get_user($this->auth->id);
				$map["_id"]= $dat['orderid'];
				$map["__v"]= 0;
				if ($this->version==3) {
					$map["pay"]=  $dat['pay']/$this->feilv;
				}else{
					$map["pay"]=  $dat['pay'];
				}

				$map["buytime"]=  $dat['buytime'];
				$map["unionid"]= $dat['unionid'];
				$map["userId"]= $dat['uid'];
				$map["nickname"]= $user['nickname'];
				$map["headimgurl"]=  $user['avatar'];
				$map["restmoney"]= 21;
				$map["first"]= 0;
				$map["win"]= $dat['peifu']>0?$dat['peifu']:0;
				$map["read"]= 0;
				$map["yongMoney"]= 0;
				$map["isControl"]= 0;
				$map["creattime"]= date('Y-m-d H:i:s',$dat['createtime']);//"2019-03-17T07:51:17.951Z";
				$map["mode"]= $dat['mode'];


				if ($dat['result']==0) {
					$result=0;
				}else{
					$result=(float)$dat['result'];
				}
				if ($this->version==3) {
					$map["now"]= $dat['now']/46400;
					$map["will"]= $result/46400;
				}else{
					$map["now"]=  (float)$dat['now'];
					$map["will"]= $result;
				}
				$map["result"]= $dat['peifu']>0?1:0;
				$map["buyDirection"]=  $dat['buyDirection'];
				$map["state"]= $dat['peifu']>0?1:0;
				$map["isbot"]= 0;
				$map["heyueindex"]= 1;
				$map["heyue"]= "BTC";
				echo json_encode($map);
			}
			public function getbase(){
				echo '{"data":1,"result":[{"_id":"6055aa7597cce055f6dc62b5","__v":0,"creattime":"2021-03-20T07:55:33.320Z","moneyarray":["100.00","200.00","300.00","500.00","1000.00","2000.00","3000.00","5000.00","10000.00"],"disable":true,"type":"alipay","name":"支付宝宝","appurl":"http://ismn96.cn:8001/outpay/fxpay","wxurl":"http://ismn96.cn:8001/outpay/fxpay","value":"0","label":"支付宝"}]}';exit;
			}

			public function setorder(){
				//以后押注数据前面要加一个数据正确性验证
				$this->checknoworder();
				$map=$this->request->param();
				if(abs($map['pay'])<5){
					return -3;
					exit;
				}
				if ($this->version==3) {
					$map['pay']=$map['pay']*$this->feilv;
				}
				$xmap=-3;
				$update=0;
				$ordercount=$this->checkdata();
				if ($ordercount>=$this->view->site['ordercount']) {

					return -3;
					exit;
				}
				//事务开始
				// 启动事务
				$koufei=abs(intval($map['pay']));
				$fmap['id']=$this->auth->id;
				$point=Db::name('User')->where($fmap)->value('point');

				if ($point<$koufei) {
					$xmap=-3;//-1
				}else{
					Db::startTrans();
					try{
						//扣掉积分
						$r=Db::name('User')->where($fmap)->setDec('point',$koufei);
						if ($r) {
							$map['now']=$this->xredis->get($this->prefix.'_now_val');
							$map['status']=0;
							$map['createtime']=time();
							$map['uid']=$this->auth->id;
							$map['result']='';
							$map['peifu']=0;

							$id=0;$idxx=0;
							$whs=array();$whs['status']=$map['status'];$whs['createtime']=$map['createtime'];$whs['uid']=$map['uid'];
							$idxx=Db::name('biquan_dat')->where($whs)->count();
							if($idxx==0){
								$id=Db::name('biquan_dat')->insertGetid($map);
								if ($id>0) {
									// $this->checkxdui($map);
									$this->daili->dailicount($this->auth->id,$koufei*100);
									//把当前数据缓存到redis中
									$map['id']=$id;
									$dat=$this->save_now($map);
									$update=1;
									$orderid=md5($id);
									Db::name('biquan_dat')->where('id='.$id)->setfield('orderid',$orderid);
									Db::name('biquan_dat')->where('id='.$id)->setfield('ifkill',$dat['ifkill']);
									Db::commit();
								}else{
									Db::rollback();

									$xmap=-3;
									$update=0;
								}
							}else{
								Db::rollback();
								$xmap=-3;
								$update=0;
							}
						}
						// 提交事务
					} catch (\Exception $e) {
						// 回滚事务
						Db::rollback();
						//echo 11;exit;
						$xmap=-3;//-3
						$update=0;
					}
					if ($update) {
						$xmap=array();
						$xmap['id']=$orderid;
						if ($this->version==3) {
							$xmap['now']=(float)$map['now']/46400;
						}else{
							$xmap['now']=(float)$map['now'];
						}
						$xmap['data']=1;
						$xmap['count']=$ordercount;
						$this->xredis->del('psgeMeOrder'.$this->auth->id);
						$this->setmyorder();
					}
				}
				echo json_encode($xmap);
			}


			////////////////////////////xin///////////////////

			//x秒内下的单超kill_line 则关小黑屋
			private function checknoworder($sec=3,$kill_line=2){
				$where['createtime']=array('gt',(time()-$sec));
				$where['uid']=$this->auth->id;
				$count=Db::name('biquan_dat')->where($where)->count();
				if ($count>=$kill_line) {
					Db::name('user')->where('id='.$this->auth->id)->setfield('ifpay',0);
				}
				return $count;
			}
			private function checkxdui($data='',$sec=3){
				$where['createtime']=array('gt',(time()-$sec));

				$data=Db::name('biquan_dat')->where($where)->order('id desc')->find();
				if ($data) {
					if ($dat['buyDirection']!=$data['buyDirection']&&$dat['pay']==$data['pay']) {
						Db::name('user')->where('id='.$this->auth->id)->setfield('ifpay',0);
						Db::name('user')->where('id='.$data['uid'])->setfield('ifpay',0);
					}
				}

				return ;
			}
			////////////////////////////xin///////////////////




			public function getOther(){
				$name=$this->request->param('name');
				switch ($name) {
					case 'ggopen':
						$msg='{"_id":"5c9e08b6b8163943acba8a3f","name":"ggopen","createtime":"2019-06-13T09:26:21.589Z","types":1,"state":1}';
						break;
					case 'huilv':
						$msg='{"_id":"sss","name":"huilv","master":"1","content":"汇率","cid":{"low":"6.70752","heigh":"6.85011","yestoday":"6.72400","today":"6.72300","updowns":"-0.1500","updown":"-0.0100"},"createtime":"2019-03-17T01:24:49.008Z","types":1,"state":1}';
						break;
					case 'users':
						$map["content"]= str_replace('http://','',$this->view->site['site_url']);
						$map["types"]= $this->feilv;
						$map["state"]= 1;

						$map["master"]= 1;
						$cid["outurl"]= str_replace('http://','',$this->view->site['site_url']).','.str_replace('http://','',$this->view->site['gotosite']);
						$cid["payurl"]= str_replace('http://','',$this->view->site['site_url']);
						$cid["downurl"]= $this->view->site['site_url'];
						$map["cid"]=$cid;
						$msg= json_encode($map);
						break; 
					default:
						$map["content"]= str_replace('http://','',$this->view->site['site_url']);
						$map["types"]= $this->feilv;
						$map["state"]= 1;
						$map["master"]= 1;
						$cid["outurl"]= str_replace('http://','',$this->view->site['site_url']).','.str_replace('http://','',$this->view->site['gotosite']);
						$cid["payurl"]= str_replace('http://','',$this->view->site['site_url']);
						$cid["downurl"]= $this->view->site['site_url'];
						$map["cid"]=$cid;
						$msg= json_encode($map);
						break;
				}
				echo $msg;

			}
			public function getOthers(){

				$dat=$this->request->param();
				if($dat['name']=='dypayinfo'){
					echo '[{"_id":"5fe9144e6d0b2b5ba5fdc42e","content":"","name":"dypayinfo","cid":{"yellomoney":"386.84","paykefuurl01":"/index/biquan/pay","paykefuurl":"/index/biquan/pay","lv100":{"payurl":"/index/biquan/pay","kefuurl":"sh"},"lv200":{"payurl":"/index/biquan/pay","kefuurl":"sh"},"lv300":{"payurl":"/index/biquan/pay","kefuurl":"sh"},"lv500":{"payurl":"/index/biquan/pay","kefuurl":"sh"},"lv1000":{"payurl":"/index/biquan/pay","kefuurl":"sh"},"lv2000":{"payurl":"/index/biquan/pay","kefuurl":"sh"},"txkefuurl":"/index/biquan/pay"},"createtime":"2021-03-24T07:47:47.060Z","types":0,"state":1,"array":[]}]';exit;
				}else{
					echo '[{"_id":"5a4ae89a6024c506f7701176","name":"guestimg","content":"'.$this->view->site['site_kefu'].'","txkefuurl":"'.$this->view->site['site_kefu'].'","createtime":"2019-03-13T14:04:34.181Z","types":1,"state":1}]';
				}


			}
			public function yonglist(){
				echo "";
			}

			public function getkline(){
				$size=$this->request->param('size');
				if ($size==39) {
					echo '[{"time":"19:41","data":["19:41",303033.52,303093.69,303013.01,303093.69]}{"_id":"5c8a39c2f4f2f33291c0bfbd","__v":0,"time":"19:22","creattime":"2019-03-14T11:23:46.777Z","data":["19:22",303355.01,303295.21,303292.78,303355.01]}]';
				}elseif($size==79){
					echo '[{"time":"19:42","data":["19:42",303034.31,303107.45,303013.01,303107.45]},{"_id":"5c8a39c2f4f2f33291c0bfbd","__v":0,"time":"19:22","creattime":"2019-03-14T11:23:46.777Z","data":["19:22",303355.01,303295.21,303292.78,303355.01]}]';
				}else{
					for($i=0;$i<20;$i++){
						if($i>0){
							$dat["_id"]= "5c89bc5ef4f2f33291c08467";
							$dat["__v"]= 0;
							$dat["creattime"]= "2019-03-14T02:28:46.520Z";
						}
						$dat["time"]= "10:".(27-$i);
						$dat["data"]=array("10:27", 301570.48, 301604.04, 301563.99, 301626.12);
						$map[$i]=$dat;
					}
					echo json_encode($map);
				}

			}

			public function rechargeAll(){
				$data=array();$user=array();
				$where['status']=array('neq',0);
				$where['uid']=$this->auth->id;
				$list=db::name('history')->where($where)->order('id desc')->select();
				foreach ($list as $key => $aa) {
					$user[$key]['_id']=$aa['uid'];
					$user[$key]['__v']=0;
					$user[$key]['money']=round($aa['cash_fee']/6.7,2);
					$user[$key]['unionid']="xx";
					$user[$key]['rechangopenid']="xx";
					$user[$key]['nickname']="精秀特群";
					$user[$key]['headimgurl']="";
					$user[$key]['orderid']=$aa['out_trade_no'];
					$user[$key]['token']="xx";
					$user[$key]['creattime']=date('Y-m-d H:i:s',$aa['createtime']);
					$user[$key]['state']=1;
					$user[$key]['restmoney']=(float)$aa['cash_fee'];
					if ($this->version==3) {
						$user[$key]['realmoney']=(float)$aa['cash_fee'];
						$user[$key]['huilv']=$this->feilv;
					}


				}
				$data['total']=1;
				$data['page']=1;
				$data['size']=15;
				$data['pageSum']=1;
				$data['data']=$user;

				echo json_encode($data);exit;

			}
			public function gethomeimg(){

				echo '[{"_id":"fff","name":"homeimg","content":"'.$this->view->site['site_kefu'].'","createtime":"2019-03-13T14:04:38.701Z","types":1,"state":1},{"_id":"5a4ae8aa6024c506f7701177","name":"homeimg","content":"'.$this->view->site['site_kefu'].'","createtime":"2019-03-13T14:04:38.701Z","types":1,"state":1},{"_id":"5a4e4b75e147f74bfc2bcb04","name":"homeimg","content":"'.$this->view->site['site_kefu'].'","createtime":"2019-03-13T14:04:38.701Z","types":1,"state":1}]';

			}
			public function lognlog(){
				echo '1';
			}
			public function getonly(){
				$map["data"]= 1;
				$result["total"]= 8;
				for($j=1;$j<2;$j++){
					$resultx[$j]["_id"]= "5cc13dbab5c0d5372c42f205";
					$resultx[$j]["__v"]= 0;
					$resultx[$j]["tab"]= "赌球模板";
					$resultx[$j]["title"]= "R组";
					$resultx[$j]["remark"]= "R组";
					$resultx[$j]["content"]= "";
					$resultx[$j]["banner"]= "xxxx";
					$resultx[$j]["shoptoplvid"]= "5c76e7324f8ec36a30468010";
					$resultx[$j]["author"]= "二维码切换";
					$resultx[$j]["bookid"]= "";
					$resultx[$j]["openid"]= "666666";
					$resultx[$j]["replylist"]= [];
					$resultx[$j]["deleted"]= false;
					$resultx[$j]["last_reply_at"]= "2019-04-25T04:55:22.027Z";
					$resultx[$j]["update_at"]= "2019-04-25T04:55:22.027Z";
					$resultx[$j]["create_at"]= "2019-04-25T04:55:22.027Z";
					$resultx[$j]["collect_count"]= 0;
					$resultx[$j]["vcount"]= 0;
					$resultx[$j]["visit_count"]= 0;
					$resultx[$j]["reply_count"]= 0;
					$resultx[$j]["wxcontect"]= false;
					$resultx[$j]["lock"]= false;
					$resultx[$j]["good"]= false;
					$resultx[$j]["top"]= false;
					$resultx[$j]["isMe"]= false;
					for($i=1;$i<2;$i++){
						$listx[$i]["status"]= "success";
						$listx[$i]["uid"]= 1556168132259;
						$listx[$i]["url"]= $this->view->site['indeximg'];
						$listx[$i]["name"]= "R1+阿本";

					}
					$resultx[$j]["list"]= $listx;
				}
				$result["result"]=$resultx;
				$map["result"]=$result;
				echo json_encode($map);
			}
			public function thrmm123Num(){
				$data=array();$datas=array();
				$mydaili=$this->daili->mydaili($this->auth->id);

				$ids='';
				$types=$this->request->param('types');
				$type=$this->request->param('type');
				switch ($types) {
					case 1:
						$ids=$mydaili['onefatherids'];
						break;
					case 2:
						$ids=$mydaili['twofatherids'];
						break;
					case 3:
						$ids=$mydaili['thrfatherids'];
						break;
					case 4:
						$ids=$mydaili['forfatherids'];
						break;
					case 5:
						$ids=$mydaili['fivfatherids'];
						break;
					case 6:
						$ids=$mydaili['sixfatherids'];
					case 7:
						$ids=$mydaili['sevfatherids'];
						break;
					default:
# code...
						break;
				}

				$datas=$this->getmyteams('id',$ids,$type,$types);

				$data['total']=1;
				$data['index']='';
				$data['size']=500;
				$data['page']=1;
				$data['data']=$datas;

				echo json_encode($data);exit;
			}

			public function getmyteams($feile='fatherid',$ids,$type=2,$dengji=0){
				//print_r($ids);exit;
				$datas=array();$where=array();
				if($ids!=''){
					$nn=strpos($ids,",");
					if($nn>0){
						$where[$feile]=array('in',$ids);
					}else{
						//echo $ids;exit;
						$where[$feile]=$ids;
					}  


					$list=db::name('user')->where($where)->order('id desc')->select();

					foreach ($list as $key => $aa) {
						$money=db::name('biquan_dat')->where('uid='.$aa['id'])->sum('pay');
						$user=$this->get_user($aa['id']);
						$datas[$key]['_id']="5c89c4a22ce43a3283d133c8";
						$datas[$key]['__v']=0;
						$datas[$key]['unionid']="oxl9I0l45e3veuDKUiRcinTZckS0";
						$datas[$key]['nickname']=$user['nickname'];
						$datas[$key]['headimgurl']=$user['avatar'];
						$datas[$key]['pay']=round($money/$this->feilv,2);
						$datas[$key]['rechargetotal']=round($money/$this->feilv,2);
						$datas[$key]['grade']=$dengji;
						$datas[$key]['addmoney']=round($money/$this->feilv,2);
						$datas[$key]['masterunionid']="oxl9I0vfNuxP7nMsO5lHizyml4Gs";
						$datas[$key]['creattime']=date('Y-m-d H:i:s',$aa['createtime']);
					}

				}

				return $datas;

			}
			public function getmyteamlist($feile='fatherid',$ids,$type=2,$dengji=0){
				$datas=array();$where=array();
				$where[$feile]=array('in',$ids);
				if($dengji>0){
					$where['dengji']=$dengji;	
				}

				if($type==1){
					$where['createtime']=array('gt',$this->todaystr);	
				}

				$list=db::name('yonjin_jl')->where($where)->order('id desc')->select();

				foreach ($list as $key => $aa) {
					$user=$this->get_user($aa['uid']);
					$datas[$key]['_id']="5c89c4a22ce43a3283d133c8";
					$datas[$key]['__v']=0;
					$datas[$key]['unionid']="oxl9I0l45e3veuDKUiRcinTZckS0";
					$datas[$key]['nickname']=$user['nickname'];
					$datas[$key]['headimgurl']=$user['avatar'];
					$datas[$key]['pay']=round($aa['money']/100/$this->feilv,2);
					$datas[$key]['rechargetotal']=round($aa['money']/100/$this->feilv,2);
					$datas[$key]['grade']=$aa['dengji'];
					$datas[$key]['addmoney']=round($aa['yonjin']/100/$this->feilv,2);
					$datas[$key]['masterunionid']="oxl9I0vfNuxP7nMsO5lHizyml4Gs";
					$datas[$key]['creattime']=date('Y-m-d H:i:s',$aa['createtime']);
				}



				return $datas;

			}
			public function myteamorder(){

				$data=array();$datas=array();

				$type=$this->request->param('type');
				$datas=$this->getmyteamlist('fatherid',$this->auth->id,$type);

				$data['total']=1;
				$data['index']='';
				$data['size']=30;
				$data['pageSum']=1;
				$data['data']=$datas;

				echo json_encode($data);exit;
			}
			public function getallm($ids){
				$datas=array();$where=array();$wheres=array();
				$where['uid']=array('in',$ids);
				$where['fatherid']=$this->auth->id;
				$allget=db::name('yonjin_jl')->where($where)->sum('yonjin');
				$where['createtime']=array('gt',$this->todaystr);
				$todayget=db::name('yonjin_jl')->where($where)->sum('yonjin');

				$wheres['uid']=array('in',$ids);
				$all=db::name('biquan_dat')->where($wheres)->sum('pay');
				$wheres['createtime']=array('gt',$this->todaystr);
				$today=db::name('biquan_dat')->where($wheres)->sum('pay');

				$datas['all']=$all/$this->feilv;
				$datas['today']=$today/$this->feilv;
				$datas['allget']=$allget/100/$this->feilv;
				$datas['todayget']=$todayget/100/$this->feilv;

				return $datas;
			}
			public function allgetmoney(){
				$data=array();$datas=array();
				$mydaili=$this->daili->mydaili($this->auth->id);

				$one=$this->getallm($mydaili['onefatherids']);
				$two=$this->getallm($mydaili['twofatherids']);
				$three=$this->getallm($mydaili['thrfatherids']);
				$four=$this->getallm($mydaili['forfatherids']);
				$five=$this->getallm($mydaili['fivfatherids']);
				$six=$this->getallm($mydaili['sixfatherids']);
				$seven=$this->getallm($mydaili['sevfatherids']);


				$data['one']=$one;
				$data['two']=$two;
				$data['three']=$three;
				$data['four']=$four;
				$data['five']=$five;
				$data['six']=$six;
				$data['seven']=$seven;

				echo json_encode($data);exit;
			}

			public function getmcount(){
				$mydaili=$this->daili->mydaili($this->auth->id);
				$todayall=$mydaili['onefather']+$mydaili['twofather']+$mydaili['thrfather']+$mydaili['forfather']+$mydaili['fivfather']+$mydaili['sixfather']+$mydaili['sevfather'];
				echo '{"onenum":'.$mydaili['onefather'].',"twonum":'.$mydaili['twofather'].',"threenum":'.$mydaili['thrfather'].',"fournum":'.$mydaili['forfather'].',"fivenum":'.$mydaili['fivfather'].',"sixnum":'.$mydaili['sixfather'].',"sevennum":'.$mydaili['sevfather'].',"todayall":'.$todayall.'}';
				}
				public function getrank(){
					echo '[]';
				}

				public function myinfo(){
					if (!isset($this->view->user)) {
						echo '{"nickname":"游客20825","cashtotal":0,"qq":0,"state":1,"unionid":"xxx000","money":0,"rechargetotal":0,"yongMoney":0,"headimgurl":"/game/qutou/biu.png","cashopenid":"1"}';
					}else{
						$name=$this->user['nickname'];
						$allyongjin=db::name('yonjin_jl')->where('fatherid='.$this->auth->id)->sum('yonjin');
						$allyongjins=db::name('user_count')->where('uid='.$this->auth->id)->sum('awardok');
						if ($this->version==3) {
							$map["yongMoney"]= $allyongjins/100/$this->feilv;
							$map["money"]= $this->view->user['point']/$this->feilv;
						}else{
							$map["yongMoney"]= $allyongjins/100;
							$map["money"]= $this->view->user['point'];
						}
						$map["yongMoneys"]= $allyongjins/100/$this->feilv;
						$map["money"]= round($map["money"],2);
						$map["cashtotal"]= 2.2;
						$map["mhuilv"]= $this->feilv;//qutou
						$map["state"]= 1;
						$map["unionid"]=$this->auth->id;
						$map["phone"]=  $this->view->user['mobile'];
						$map["headimgurl"]= $this->user['avatar'];
						$map["rechargetotal"]= 0;
						$map["winlose"]= 1;//$this->countdata();
						$map["nickname"]= mb_substr($this->view->user['nickname'],0,4)."：".$this->user['id'];//mb_substr($this->view->user['nickname'],0,4)."：".$this->user['id'];;
						$map["rank"]= 10;
						$map["lv"]= 1;
						$map["creattime"]= "2019-03-09T05:30:51.383Z";
						$map["role"]= "person";
						$map["cashopenid"]= 1;
						echo json_encode($map);
					}

				}

				public function onlinecount(){
					$map['usercount']=mt_rand(800,1500);
					$map['0']=0;
					$map['down']=5;
					echo json_encode($map);
				}
				public function urlmake(){
					/* if ($this->version==3) {
					   $gotourl=$this->view->site['site_enter']."/index.php/Index/biquan/index/fid/".$this->auth->id."/type/1/tid/".$this->view->site['ewmcount'].".html";
					   echo '{"data":1,"url":"'.$gotourl.'"}';
					   }else{}*/
					$gotourl=$this->view->site['site_enter']."/jxtq.php/Index/user/wxlog/fid/".$this->auth->id."/type/1/tid/".$this->view->site['ewmcount'].".html";
					echo '{"data":1,"url":"'.$gotourl.'"}';


				}
				private function xxxxxxxxxxxxx(){}
				public function test(){
					$keys=$this->xredis->keys("*".$this->prefix."*");
					print_r($keys);


				}
				public function clearn(){
					$keys= $this->xredis->keys('*qutou*');
					foreach ($keys as $key => $value) {
						$this->xredis->delete($value);
						echo "\n".$value;
					}
				}
				//把某一个时间点的上升下降数据缓存起来，用户ganrao程序
				private function save_now($map=''){
					$nowdat=$this->xredis->get($this->prefix.'setorder'.$map['buytime']);
					if ($nowdat) {
						$dat=json_decode($nowdat,true);
						if ($map['buyDirection']==1) {
							$dat['up_val']+=$map['pay'];
						}else{
							$dat['down_val']+=$map['pay'];
						}
					} else {
						$dat['buytime']=$map['buytime'];
						$dat['now']=$map['now'];
						//把有押注的时间点推入订单线。
						$this->xredis->lpush($this->prefix.'biquan'.'_order_line',json_encode($dat));
						if ($map['buyDirection']==1) {
							$dat['up_val']=$map['pay'];
							$dat['down_val']=0;
						}else{
							$dat['up_val']=0;
							$dat['down_val']=$map['pay'];
						}    
					}
					$dat['ifkill']=$this->get_kill($dat);

					$this->xredis->set($this->prefix.'setorder'.$map['buytime'],json_encode($dat));
					return $dat;
				}
				//计算本局是否控制
				//0。公平，1.必杀 2，必赢
				private function get_kill($dat=''){
					//是否杀的逻辑算法--begin
					$kill=0;
					if ($dat['up_val']>$dat['down_val']) {
						$cha=$dat['up_val']-$dat['down_val'];
					}else{
						$cha=$dat['down_val']-$dat['up_val'];
					}
					$cha=$cha*1.85;//输赢大小
					if ($this->addon['waterlever']<=$cha) {
						$kill=1;
					}else{
						//落入几率
						$x=mt_rand(1,100);
						if ($this->addon['percent']>=$x&&$this->addon['ifkeep']==1) {
							$kill=1;
						}
					}
					return $kill;
				}
				private static function getMillisecond() {
					list($t1, $t2) = explode(' ', microtime());
					return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
				}

				private function countdata($data=''){
					$where['uid']=$this->auth->id;
					// $where['peifu']=0;
					$count=Db::name('biquan_dat')->where($where)->count();
					if ($count) {
						return $count;
					}else{
						return 0;
					}

				}
				//对数据安全进行认证
				private function checkdata($status=0){
					$where['uid']=$this->auth->id;
					$where['status']=$status;
					$count=Db::name('biquan_dat')->where($where)->count();
					if ($count) {
						return $count;
					}else{
						return 0;
					}

				}
				private  function get_user($uid=0,$force=0){
					if ($uid>0) {
						$user=json_decode($this->xredis->get($this->prefix.'user'.$uid),true);
						if (!$user||$force) {
							$user=Db::name('user')->field('nickname,avatar')->where('id='.$uid)->find();
							if (!$user) {
								$user['nickname']='游客';
								$user['avatar']='#';
							} 
							$this->xredis->set($this->prefix.'user'.$uid,json_encode($user));
						}
					}
					return $user;
				}
				/**
				  }
				  }
				 * 初始化游戏
				 * @param string $name
				 * @return array
				 */
				private function init_game(){
					$run_count= $this->game->cache_get('run_count'.$this->todaystr);
					if (!$run_count) {
						$this->game->cache_set('roomid',1);
						//$data 当前开奖序列
						$tomap['createtime']=$this->todaystr;
						$todatay=Db::name('run_count')->where($tomap)->count();
						if(!$todatay){
							$map['uid']=0;
							$map['allin']=0;
							$map['allout']=0;
							$map['result']=0;
							$map['note']=date('Y/m/d')."记录！";
							$map['createtime']=$this->todaystr;;
							Db::name('run_count')->insert($map);
						}
						$this->game->cache_set('shareconfig',$this->view->site);
						$this->game->cache_set('run_count'.$this->todaystr,$this->todaystr);
					}
					$cmap['uid']=$this->auth->id;
					$cmap['createtime']=$this->todaystr;
					$user_count= $this->game->cache_get('user_count'.$this->todaystr.$this->auth->id);
					if (!$user_count) {
						$this->daili->relation($this->auth->id);
						$user_count=Db::name('user_count')->where($cmap)->count();
						if(!$user_count){
							Db::name('user_count')->insert($cmap);
						}
						$this->game->cache_set('user_count'.$this->todaystr.$this->auth->id,$this->auth->id);
					}

					$this->fangfeng();
					return true;
				}
				private function fangfeng(){
					if (!is_file(RUNTIME_PATH   . 'enter.php')) {
						$str='<?php return array(\'site_enter\'=>\''.$this->view->site['site_enter'].'\',\'gotosite\'=>\''.$this->view->site['gotosite'].'\');';
						$fp=fopen(RUNTIME_PATH   . 'enter.php',"w");//写文件输出用于检测先删掉4.txt
						fwrite($fp,$str);
						fclose($fp);
					}
					return true;
				}

				//取款
				public function redpush(){
					$jxpay=get_addon_config('jxpay');
					$where['uid']=$this->auth->id; 
					$where['status']=array('gt',0);
					$game_time=Db::name('biquan_dat')->where($where)->count();

					$soncount=Db::name('user')->where('fatherid='.$this->auth->id)->count();//下级数大于5人，不受游戏次数限制
					if (1) {//$jxpay['gametime']<=$game_time||$soncount>=5
						$data=$this->wxcashs(1,$this->request->param('money'));
						echo 1;
					}else{
						echo -1;
					}

					//"-1"通道繁忙稍后尝试
					//-8服务器维护中
					//-12 通道繁忙，备用通道开启


				}

				//提现
				public function wxcashs($type=1,$money=0){
					$data=1;

					/*$type=$this->request->param('type');*/
					$fee=$money;

					$fee=$fee*$this->feilv;


					$ordercount=$this->countdata();

					if(1){//$ordercount>=1
						//防止卡包
						$this->game->cache_set('lock_balance'.$this->auth->id,0);
						$lock_balance=$this->game->cache_get('lock_balance'.$this->auth->id);
						if ($lock_balance!=0) {
							$data=-1;
							$map['msg']='请耐心等待客服审核,blance!';
						}else{
							$map['msg']='提现申请已提交，请耐心等待客服审核!';
							//启动异步取款
							$qiyue=controller('Qiyue','controller');

							$field='point';

							$qiyue->nourl_pay($this->auth->id,$fee,'入款'.$fee,$field);//.$str.$fee
						}
					}else{
						$data=-1;
					}
					//2提示
					if ($this->version==3) {
						return $data;
					}else{
						echo json_encode($data);exit;
					}

				}


				public function outmoney(){
					;
				}
				public function pay(){
					$aa=$this->request->param('money');
					$feilv=$this->xredis->get($this->prefix.'_now_val')/46400;
					//$aa=$aa*$feilv;
					$payurl='';
					$payType=$this->view->site['paytype'];

					switch ($payType) {
						case 1:
							$payurl=$this->view->site['site_url'].'/index.php/Index/sfpay/yybpay/aa/'.$aa.'/uid/'.$this->auth->id;
							break;
						default:
							$payurl=$this->view->site['site_url'].'/index.php/Index/index/debugx/aa/'.$aa;
							break;
					}
					header('location: '.$payurl);exit;
				}
				public function payx($aa=0){
					echo "测试中";
				}

				public function psgeMeOrder(){
					if (!isset($this->view->user)) {
						echo -1;
					}else{
						$str=$this->xredis->get($this->prefix.'str_psgeMeOrder'.$this->auth->id);
						if (!$str) {
							$str=$this->setmyorder();
						}
						echo $str;

					}

				}


	}
	?>
